package ar.com.nexoweb.actualidadbasquet.network;

import java.util.List;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import ar.com.nexoweb.actualidadbasquet.data.AsyncTaskCompletionListener;
import ar.com.nexoweb.actualidadbasquet.data.XmlHandler;
import ar.com.nexoweb.actualidadbasquet.entities.Noticia;

public class RssFeedAsyncTask extends
		AsyncTask<String, Void, List<Noticia>> {
	private ProgressDialog Dialog;
	String response = "";
	List<Noticia> rssStr;
	Activity _context;
	private AsyncTaskCompletionListener callback;

	public RssFeedAsyncTask(Activity _context) {
		this._context = _context;
		this.callback = (AsyncTaskCompletionListener) _context;
	}

	@Override
	protected void onPreExecute() {
		Dialog = new ProgressDialog(_context);
		Dialog.setMessage("Actualizando...");
		Dialog.show();

	}

	@Override
	protected List<Noticia> doInBackground(String... urls) {
		try {
			String feed = urls[0];
			XmlHandler rh = new XmlHandler();
			rssStr = rh.getLatestArticles(feed);
		} catch (Exception e) {
		}
		return rssStr;

	}

	@Override
	protected void onPostExecute(List<Noticia> result) {
		Dialog.dismiss();
		callback.onTaskComplete(result);

	}

}
